﻿namespace KinonekoSoftware.CodariaDB.Runtimes.Abstractions
{
    public interface IObjectPool
    {
        /// <summary>
        /// 获取或者创建对象。
        /// </summary>
        /// <param name="factory">返回指定类型对象的工厂方法。</param>
        /// <param name="cache">是否从缓存中获取。</param>
        /// <typeparam name="T">指定的对象类型。</typeparam>
        /// <returns>返回指定类型的对象</returns>
        T GetOrCreate<T>(Factory<T> factory, bool cache = true) where T : EmbeddedObject;


        /// <summary>
        /// 
        /// </summary>
        /// <param name="cache">是否从缓存中获取。</param>
        /// <typeparam name="T">指定的对象类型。</typeparam>
        /// <returns></returns>
        T Get<T>(bool cache = true) where T : EmbeddedObject;

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        bool Has<T>() where T : EmbeddedObject;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        bool Has(Type type);

        /// <summary>
        /// 插入或者更新实例
        /// </summary>
        /// <param name="instance">插入或者更新的实例。</param>
        /// <param name="insert">是否为插入</param>
        /// <typeparam name="T">实例类型。</typeparam>
        /// <returns>返回操作完成的实例本身。</returns>
        T Set<T>(T instance, bool insert = false) where T : EmbeddedObject;

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        bool Unset<T>(out T value) where T : EmbeddedObject;

        // /// <summary>
        // ///
        // /// 
        // /// </summary>
        // /// <returns></returns>
        bool Unset(string keyName);
    }
}